﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Family.Data.DBRepositories;
using Family.Data.Factories;

public partial class Controls_FamilyCalendar : System.Web.UI.UserControl
{
    private OrderRepository oRepo;

    protected Controls_FamilyCalendar()
    {
        oRepo = new OrderRepository(WebFactory.CurrentSession);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCalendar(DateTime.Now);
        }
    }

    public void BindCalendar(DateTime date)
    {
        var numberOfDays = DateTime.DaysInMonth(date.Year, date.Month);

        dateRow.Cells.Clear();
        amountRow.Cells.Clear();

        for (var i = 1; i <= numberOfDays; i++)
        {
            var dateTime = new DateTime(date.Year, date.Month, i);
            var amount = oRepo.GetAmountByDate(dateTime);

            var c1 = new TableCell();
            c1.CssClass = "dateCell";
            c1.Controls.Add(new Label {Text = i.ToString()});

            var c2 = new TableCell();
            c2.CssClass = "amountCell";
            c2.Controls.Add(new Label {Text = amount.ToString("N2")});

            dateRow.Cells.Add(c1);
            amountRow.Cells.Add(c2);
        }
    }
}